using UnityEngine;
using System.Collections;

public class protoSTB : MonoBehaviour {
	public bool testing = false;
	public int curPlayers = 0;
	public playerManager p;
	// Use this for initialization
	void Start () {
		networkView.group = 1;
		p = GameObject.Find("playerManager").GetComponent<playerManager>();
	}
	
	// Update is called once per frame
	void Update () {
		if(testing == true){
			if(curPlayers == p.pNum){
				Network.RemoveRPCsInGroup(0);
				Network.RemoveRPCsInGroup(1);
				networkView.RPC("ProtoSTBLoadLevel",RPCMode.AllBuffered);
			}
		}
				
	
	}
	void OnTriggerEnter(Collider other){
		PlayerScript p = other.GetComponent<PlayerScript>();
		if(p != null){
			testing = true;
			curPlayers += 1;
		}
	}
	void OnTriggerExit(Collider other){
		PlayerScript p = other.GetComponent<PlayerScript>();
		if(p != null){
			curPlayers -= 1;
			if(curPlayers == 0){
				testing = false;
			}
		}
	}
	[RPC]
	void ProtoSTBLoadLevel(){
		Network.SetSendingEnabled(0, false);
		Network.isMessageQueueRunning = false;
		Network.SetLevelPrefix(1);
		Application.LoadLevel("BossScene");
		Network.isMessageQueueRunning = true;
		Network.SetSendingEnabled(0,true);
	}
}
